#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    int findPoisonedDuration(vector<int>& timeSeries, int duration)
    {
        int n = timeSeries.size();
        int drug = 0;
        for (int i = 0; i < n; i++)
        {
            if (i + 1 != n && timeSeries[i + 1] - timeSeries[i] <= duration - 1)
                drug += timeSeries[i + 1] - timeSeries[i];
            else
                drug += duration;
        }
        return drug;
    }
};